﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using WX.WMS.BLL;
using WX.WMS.Common;
using WX.WMS.DataModel;
using Microsoft.Reporting.WebForms;

public partial class Report_ReportView : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        LocalReport report;
        string ID = string.Empty;
        if (!IsPostBack)
        {
            switch (Convert.ToString(Request.QueryString["type"]))
            {
                case "groupstore":
                    this.ReportView1.ProcessingMode = ProcessingMode.Local;
                    report = new LocalReport();
                    report = this.ReportView1.LocalReport;
                    report.ReportPath = "Report/ReportGroupStore.rdlc";
                    report.DataSources.Add(GetGroupStore());

                    report.Refresh();
                    break;

                case "inout":
                    this.ReportView1.ProcessingMode = ProcessingMode.Local;
                    report = new LocalReport();
                    report = this.ReportView1.LocalReport;
                    report.ReportPath = "Report/ReportInOutStore.rdlc";
                    report.DataSources.Add(GetInOutStoreData());
                   
                    report.Refresh();
                    break;

                case "instock":
                    this.ReportView1.ProcessingMode = ProcessingMode.Local;
                     report = new LocalReport();
                    report = this.ReportView1.LocalReport;
                    report.ReportPath = "Report/PrintInstockBill.rdlc";
                    ID = Request.QueryString["ID"].ToString(); //"3c8d8926-1ade-4b17-8766-4541e35407d4";//
                    report.DataSources.Add(GetInstockData(ID));
                    report.DataSources.Add(GetInstockItemData(ID));
                    report.Refresh();
                    break;
                case "instockdetail":
                    this.ReportView1.ProcessingMode = ProcessingMode.Local;
                    report = new LocalReport();
                    report = this.ReportView1.LocalReport;
                    report.ReportPath = "Report/InStockDetail.rdlc";
                    ID = Request.QueryString["ID"].ToString(); //"3c8d8926-1ade-4b17-8766-4541e35407d4";//
                    report.DataSources.Add(GetInstockData(ID));
                    report.DataSources.Add(GetInstockItemData(ID));
                    report.Refresh();
                    break;
                case "instocknofloor":
                    this.ReportView1.ProcessingMode = ProcessingMode.Local;
                    report = new LocalReport();
                    report = this.ReportView1.LocalReport;
                    report.ReportPath = "Report/PrintInstockBillNoFloor.rdlc";
                    ID = Request.QueryString["ID"].ToString(); //"3c8d8926-1ade-4b17-8766-4541e35407d4";//
                    report.DataSources.Add(GetInstockData(ID));
                    report.DataSources.Add(GetInstockItemGroupData(ID));
                    report.Refresh();
                    break;
                case "outstock":
                    this.ReportView1.ProcessingMode = ProcessingMode.Local;
                    report = new LocalReport();
                    report = this.ReportView1.LocalReport;
                    report.ReportPath = "Report/PrintOutstockBill.rdlc";
                     ID = Request.QueryString["ID"].ToString(); //"3c8d8926-1ade-4b17-8766-4541e35407d4";//
                    report.DataSources.Add(GetOutstockData(ID));
                    report.DataSources.Add(GetOutstockItemData(ID));
                    report.Refresh();
                    break;
                case "outstockdetail":
                    this.ReportView1.ProcessingMode = ProcessingMode.Local;
                    report = new LocalReport();
                    report = this.ReportView1.LocalReport;
                    report.ReportPath = "Report/OutStockDetail.rdlc";
                    ID = Request.QueryString["ID"].ToString(); //"3c8d8926-1ade-4b17-8766-4541e35407d4";//
                    report.DataSources.Add(GetOutstockData(ID));
                    report.DataSources.Add(GetOutstockItemData(ID));
                    report.Refresh();
                    break;
                case "outstocknofloor":
                    this.ReportView1.ProcessingMode = ProcessingMode.Local;
                    report = new LocalReport();
                    report = this.ReportView1.LocalReport;
                    report.ReportPath = "Report/PrintOutstockNoFloorBill.rdlc";
                    ID = Request.QueryString["ID"].ToString(); //"3c8d8926-1ade-4b17-8766-4541e35407d4";//
                    report.DataSources.Add(GetOutstockData(ID));
                    report.DataSources.Add(GetOutstockItemGroupData(ID));
                    report.Refresh();
                    break;
                case "stocktake":
                    this.ReportView1.ProcessingMode = ProcessingMode.Local;
                    report = new LocalReport();
                    report = this.ReportView1.LocalReport;
                    report.ReportPath = "Report/StockTake.rdlc";
                    ID = Request.QueryString["ID"].ToString(); //"3c8d8926-1ade-4b17-8766-4541e35407d4";//
                    report.DataSources.Add(GetStockTakeItemData(ID));
                    report.Refresh();
                    break;
                case "store":
                    this.ReportView1.ProcessingMode = ProcessingMode.Local;
                    report = new LocalReport();
                    report = this.ReportView1.LocalReport;
                    report.ReportPath = "Report/Store.rdlc";
                    report.DataSources.Add(GetStoreData());
                    report.Refresh();
                    break;
                case "storeall":
                    this.ReportView1.ProcessingMode = ProcessingMode.Local;
                    report = new LocalReport();
                    report = this.ReportView1.LocalReport;
                    report.ReportPath = "Report/Store2.rdlc";
                    report.DataSources.Add(GetStoreAllData());
                    report.Refresh();
                    break;
                default:
                    break;

            }
        }
    }

    private ReportDataSource GetInOutStoreData()
    {
        ReportDataSource source = new ReportDataSource();
        source.Name = "InOutStoreView";


        source.Value = new InOutStoreReportBLL().GetInOutStoreView();

       
        return source;
    }
    private ReportDataSource GetStoreData()
    {
        ReportDataSource source = new ReportDataSource();
        source.Name = "VStoreView";
        if (Session["StoreData"] != null)
        {

            source.Value = Session["StoreData"];
          
        }
        else
        {

            source.Value = new StoreReportBLL().GetVStoreView();

        }
        return source;
    }

    private ReportDataSource GetGroupStore()
    {
        ReportDataSource source = new ReportDataSource();
        source.Name = "VGroupStoreView";
        source.Value = new GroupStore().GetGroupStoreView();
        return source;
    }

    private ReportDataSource GetStoreAllData()
    {
        ReportDataSource source = new ReportDataSource();
        source.Name = "Store_All";
        DateTime begin = DateTime.MinValue, end = DateTime.MinValue;
        if (!DateTime.TryParse(Request.QueryString["begin"].ToString(),out begin))
        { begin = DateTime.MinValue; }
        if (!DateTime.TryParse(Request.QueryString["end"].ToString(), out end))
        {
            end = DateTime.MinValue;
        }
        source.Value = new StoreReportBLLAll().GetVStoreView(begin,end);
        return source;
    }
    private ReportDataSource GetStockTakeItemData(string ID)
    {
        ReportDataSource source = new ReportDataSource();
        source.Name = "VStockTakeItem";
        source.Value = new StockTakeReportBLL().GetVStockTakeItem(ID);
        return source;
    }
    protected ReportDataSource GetInstockData(string ID)
    {
        ReportDataSource source = new ReportDataSource();
        source.Name = "VInStock";
        source.Value = new ReportBLL().GetVInstock(ID);
        return source;
    }
    protected ReportDataSource GetInstockItemData(string ID)
    {
        ReportDataSource source = new ReportDataSource();
        source.Name = "VInStockItem";
        source.Value = new ReportBLL().GetVInstockItem(ID);
        return source;
    }
    protected ReportDataSource GetInstockItemGroupData(string ID)
    {
        ReportDataSource source = new ReportDataSource();
        source.Name = "VInStockItemGroup";
        source.Value = new ReportBLL().GetVInstockItemNoFloor(ID);
        return source;
    }
    protected ReportDataSource GetOutstockData(string ID)
    {
        ReportDataSource source = new ReportDataSource();
        source.Name = "VOutStock";
        source.Value = new OutStockReportBLL().GetVOutstock(ID);
        return source;
    }
    protected ReportDataSource GetOutstockItemData(string ID)
    {
        ReportDataSource source = new ReportDataSource();
        source.Name = "VOutStockItem";
        source.Value = new OutStockReportBLL().GetVOutstockItem(ID);
        return source;
    }
    protected ReportDataSource GetOutstockItemGroupData(string ID)
    {
        ReportDataSource source = new ReportDataSource();
        source.Name = "VOutStockItemGroup";
        source.Value = new OutStockReportBLL().GetVOutstockItemNoFloor(ID);
        return source;
    }
}
